<%--
  Created by IntelliJ IDEA.
  User: LT
  Date: 2018-10-25
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/statics/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/statics/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/statics/hplus/js/jquery.min.js"></script>
    <link href="${pageContext.request.contextPath}/statics/hplus/css/animate.min.css" rel="stylesheet">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/bootstrapvalidator/bootstrapValidator.min.css">
    <script src="${pageContext.request.contextPath}/statics/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/bootstrapvalidator/bootstrapValidator.min.js"></script>
    <script>
        $(function () {
            $("#chan").bootstrapTable({
                url:'${pageContext.request.contextPath}/chan/chanpin',
                //设置每页多少条数据
                pageSize:2,
                pageList:[2,4,8,16],
                //刷新按钮
                showRefresh:true,
                height:380,
                pageNumber:1,
                columns:[
                    {
                        field:'shangpinFenlei_Id',
                        title:'类别编号',
                        align:'center'
                    },
                    {
                        field:'shangpinFenlei_Name',
                        title:'类别名称',
                        align:'center'
                    },
                    {
                        title:'操作',
                        align:'center',
                        formatter:function (value,row,index) {
                            return "<button class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\".bs-example-modal-sm\""+
                                "style='background-color: red;color: white;border:1px solid red;height:35px;\" +\n" +
                                "font-size: 14px' onclick='javascript:del("+row.shangpinFenlei_Id+")'><span style='margin-top: 1px' class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\" title='删除'><p style='float:right;margin-top: -1px'>删除</p></span></button>"+
                                "<button class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\".bs-example-modal-sm\"" +
                                " style='margin-left: 10px;height:35px;font-size: 14px;' onclick='javascript:ud("+row.shangpinFenlei_Id+")'><span style='margin-top: 1px' class=\"glyphicon glyphicon-pencil\" aria-hidden=\"true\" title='修改'><p style='float:right;margin-top: -1px'>修改</p></span></button>"
                        }
                    }],
            }) ;
        }) ;
        /**
         * 删除
         */
        var shangpinFenlei_Id;
        function del(kids){
            shangpinFenlei_Id=kids;
            $("#qwe").modal('show');
        }
        function shanchus() {
            $.post('${pageContext.request.contextPath}/shangpin/shanchu',{shangpinFenlei_Id:shangpinFenlei_Id},function(data){
                if(data!=null){
                    alert("删除成功")
                    window.location.reload();//强制刷新
                    $("#qwe").modal('hide');
                }
            })
        }

        /**
         * 添加
         */
        function toadd() {
            $("#tiajia").modal("show") ;
        }
        function tiajia(){
            var shangpinFenlei_Name=$('[name=shangpinFenlei_Name]').val();
            $.post('${pageContext.request.contextPath}/shangpin/tiajia',{shangpinFenlei_Name:shangpinFenlei_Name},function (data) {
                if (data!=null){
                    alert("添加成功！");
                    window.location.reload();//强制刷新
                    $("#tiajia").modal('hide');
                } else {
                    alert("增加失败！");
                }
            })
        }

        /**
         * 根据商品分类id修改信息
         * @type {number}
         */
        var shangpinFenlei_Id=0;
        function ud(id) {
            shangpinFenlei_Id=id;
            $("#xiugai").modal("show");
            $.post('${pageContext.request.contextPath}/shangpin/queryId',{shangpinFenlei_Id:shangpinFenlei_Id},function (data) {
               $("[name=shangpinFenlei_NameG]").val(data.shangpinFenlei_Name);
            })
        }
        function xiugai() {
            var shangpinFenlei_NameG = $("[name=shangpinFenlei_NameG]").val();
            $.post('${pageContext.request.contextPath}/shangpin/xiugai',{shangpinFenlei_Id:shangpinFenlei_Id,shangpinFenlei_Name:shangpinFenlei_NameG},function (data) {
                if (data!=null){
                    alert("修改成功!")
                    window.location.reload();//强制刷新
                    $("#xiugai").modal("hide");
                } else{
                    alert("修改失败!")
                }
            })
        }


    </script>

</head>
<body>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">产品类型设置</h3>
    </div>
    <div class="panel-body" style="height: 590px">
        <div class="row">
            <div class="col-sm-6">
                <button onclick="toadd()" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;增加</button>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <table id="chan"></table>
            </div>
        </div>

    </div>
</div>


<!---添加模态框-->
<div class="modal fade" id="tiajia">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form method="post" class="form-horizontal">
                <div class="modal-header">
                    <h4 class="modal-title" id="modelTitleId1">添加服务类型</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="shangpinFenlei_Name" class="col-sm-2 control-label">类型名称:</label>
                        <div class="col-sm-9">
                            <input  type="text" name="shangpinFenlei_Name" class="form-control" id="title1" placeholder="请输入类型名称">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">←返回</button>
                    <button type="button" class="btn btn-primary" onclick="tiajia()">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>


<!---修改模态框-->
<div class="modal fade" id="xiugai">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form method="post" class="form-horizontal">
                <div class="modal-header">
                    <h4 class="modal-title" id="modelTitleId2">添加服务类型</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="shangpinFenlei_NameG" class="col-sm-2 control-label">类型名称:</label>
                        <div class="col-sm-9">
                            <input  type="text" name="shangpinFenlei_NameG" class="form-control" id="title" placeholder="请输入类型名称">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">←返回</button>
                    <button type="button" class="btn btn-primary" onclick="xiugai()">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>


<!---删除模态框-->
<div class="modal fade" id="qwe">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="modelTitleId">提示信息</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12" id="addrole" style="height: 100px">
                        <p>确认删除信息吗？</p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary"onclick="shanchus()">删除</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>
